package com.feihao.zhou.concurrentHashMapTest;

import java.util.HashMap;

public class HashMapThreadTest {
    public static void main(String[] args) throws InterruptedException {
        HashMap<String,String> map = new HashMap<>();

        //创建线程并开启向集合添加元素：
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    map.put(i+"",i+"");
                }
            }
        }).start();

        new Thread(()->{
            for (int i = 100; i < 401; i++) {
                map.put(i+"",i+"");
            }
        }).start();

        //主线程休眠2000毫秒让新建的线程执行完任务；
        Thread.sleep(2000);

        for (int i = 0; i < 401; i++) {
            System.out.println(map.get(i+""));
        }
    }
}
